import React from 'react';
import Card from 'material-ui/lib/card/card';
import CardHeader from 'material-ui/lib/card/card-header';
import CardText from 'material-ui/lib/card/card-text';
import CardActions from 'material-ui/lib/card/card-actions';
import FlatButton from 'material-ui/lib/flat-button';

import filterStyle from './Filter.less';

export default class Filter extends React.Component {

	// 属性验证
	static propTypes = {
		onSearch: React.PropTypes.func.isRequired
	};

	static defaultProps = {
		title: '高级筛选条件',
		subtitle: '调整筛选条件可以查询更为准确的数据'
	};

	constructor(props) {
		super(props);
	}

	handleStartSearch = () => {
		let { onSearch } = this.props;

		onSearch();
	};

	render() {
		let { title, subtitle, children } = this.props;

		return ( 
			<Card initiallyExpanded={false}>
				<CardHeader
			      title={title}
			      subtitle={subtitle}
			      actAsExpander={true}
			      showExpandableButton={true} />
			    <CardText expandable={true} style={{padding: 0}}>
			    	<div className={filterStyle.filter}>
			    		{children}
			    	</div>
			    </CardText>
			    <CardActions expandable={true} style={{textAlign: 'right'}}>
			        <FlatButton label="开始查询" primary={true} onTouchTap={this.handleStartSearch} />
			    </CardActions>
			</Card>
		);
	}
}